1968B - Prefiquence - CodeForces Solution


greedy two pointers

Please click on ads to support us..

Python Code:

t = int(input())
for test in range(t):
    nm = list(map(int,input().split()))
    n = nm[0]
    m = nm[1]
    arr_a = list(input())
    arr_b = list(input())
    p1=0
    p2=0
    ans=0
    while p1<n and p2<m:
        if arr_a[p1]==arr_b[p2]:
            p1+=1
            ans+=1
        p2+=1
    print(ans)


Comments

Submit
0 Comments
More Questions

32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement